package com.ujson.base.web.exception;

import com.ujson.base.common.dto.Res;
import com.ujson.base.common.utils.LogUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;

import javax.servlet.http.HttpServletRequest;

/**
 * <h3>ujson-parent</h3>
 * <p>全局异常处理</p>
 *
 * @author JerryLiu  a1031757312@gmail.com
 * @version 1.0
 * @date 2021-11-20 12:32
 */
@Slf4j
@ControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(value = Exception.class)
    public Object exceptionHandler(HttpServletRequest req, Exception ex) {
        LogUtil.error(log, "global exception.", ex);
        return Res.fail(ex);
    }

}
